import {
  ControlController,
  ICaptionBarState,
  ICaptionBarEvent,
  ICaptionBarController,
} from '@ibiz-template/runtime';
import { ICaptionBar } from '@ibiz/model-core';

/**
 * 标题栏控制器
 *
 * @author chitanda
 * @date 2022-07-24 15:07:07
 * @export
 * @class CaptionBarController
 * @extends {ControlController}
 */
export class CaptionBarController
  extends ControlController<ICaptionBar, ICaptionBarState, ICaptionBarEvent>
  implements ICaptionBarController
{
  protected initState(): void {
    super.initState();
    this.state.caption = this.view.model.caption!;
  }

  protected async onCreated(): Promise<void> {
    await super.onCreated();

    this.view.evt.on('onViewInfoChange', ({ caption: _caption, dataInfo }) => {
      this.state.caption = `${this.view.model.caption!}${
        dataInfo ? `-${dataInfo}` : ''
      }`;
    });
  }
}
